package com.shxt.service;

import java.util.List;
import java.util.Map;

import org.apache.ibatis.session.SqlSession;

import com.shxt.data.D_File_Root_StructMapper;
import com.shxt.pojo.D_File_Root_Struct;

public class D_File_Root_StructService implements D_File_Root_StructMapper {
	
	private static D_File_Root_StructService instance = null ;
	
	public static D_File_Root_StructService getInstance(){
		if(instance==null){
			instance = new D_File_Root_StructService();
		}
		return instance;
	}

	@Override
	public int addFolder(D_File_Root_Struct dfrs) {
		SqlSession session = MyFactory.sessionFactory().openSession();
		int i = 0;
		try{
			D_File_Root_StructMapper dftsm = session.getMapper(D_File_Root_StructMapper.class);
			dftsm.addFolder(dfrs);
			session.commit();
			i++;
		}finally{
			if(session!=null){
				session.close();
			}
		}
		return i;
	}

	@Override
	public int updateFolder(D_File_Root_Struct dfrs) {
		SqlSession session = MyFactory.sessionFactory().openSession();
		int i = 0;
		try{
			D_File_Root_StructMapper dfrsm = session.getMapper(D_File_Root_StructMapper.class);
			dfrsm.updateFolder(dfrs);
			session.commit();
			i++;
		}finally{
			if(session!=null){
				session.close();
			}
		}
		return i;
	}

	@Override
	public int deleteFolder(long folderID) {
		SqlSession session = MyFactory.sessionFactory().openSession();
		int i = 0 ;
		try{
			D_File_Root_StructMapper dfrsm = session.getMapper(D_File_Root_StructMapper.class);
			dfrsm.deleteFolder(folderID);
			session.commit();
			i++;
		}finally{
			if(session!=null){
				session.close();
			}
		}
		return i;
	}

	@Override
	public List<D_File_Root_Struct> selectUserFolder(long userID) {
		SqlSession session = MyFactory.sessionFactory().openSession();
		List<D_File_Root_Struct> ldfrs ;
		try{
			D_File_Root_StructMapper dfrsm = session.getMapper(D_File_Root_StructMapper.class);
			ldfrs = dfrsm.selectUserFolder(userID);
		}finally{
			if(session!=null){
				session.close();
			}
		}
		return ldfrs;
	}

	@Override
	public List<D_File_Root_Struct> selectFolder(Map<String,String> map) {
		SqlSession session = MyFactory.sessionFactory().openSession();
		List<D_File_Root_Struct> ldfrs ;
		try{
			D_File_Root_StructMapper dfrsm = session.getMapper(D_File_Root_StructMapper.class);
			ldfrs = dfrsm.selectFolder(map);
		}finally{
			if(session!=null){
				session.close();
			}
		}
		return ldfrs;
	}

	@Override
	public List<D_File_Root_Struct> selectFolderByFolderId(
			Map<String, String> map) {
		SqlSession session = MyFactory.sessionFactory().openSession();
		List<D_File_Root_Struct> ldfrs ;
		try{
			D_File_Root_StructMapper dfrsm = session.getMapper(D_File_Root_StructMapper.class);
			ldfrs = dfrsm.selectFolderByFolderId(map);
		}finally{
			if(session!=null){
				session.close();
			}
		}
		return ldfrs;
	}

}
